package com.ujiuye.web;

import com.ujiuye.entity.Student;
import com.ujiuye.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/queryAll")
public class QueryStuServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决中文乱码
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        //调用Student的service层的查询学生方法
        StudentService ss = new StudentService();
        List<Student> list = ss.queryStudents();
        //数据绑定
        req.setAttribute("list",list); //${list}
        //req.setAttribute("stu",new Student(xxxxx));   //${stu.sname}
        //转发-->让queryStu.jsp显示数据
        req.getRequestDispatcher("queryStu.jsp").forward(req,resp);
    }
}
